package com.zrrd.spring_01;

import com.zrrd.spring_01.mapper.OrderDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author WanJl
 * @version 1.0
 * @title Main
 * @description
 * @create 2024/10/20
 */
public class Main {
    public static void main(String[] args) {
        /*第4步：测试一下*/
        //1、创建IOC容器对象，加载spring核心配置文件applicationContext.xml
        ApplicationContext context =
                new ClassPathXmlApplicationContext("applicationContext.xml");
        //2、从IOC容器中获取Bean对象(TeaService)
        //"teaService02" 是我们在applicationContext.xml的<bean>标签中配置的id属性。
        // 通过getBean()获取Bean必须以id或name为参数。如果均未获取到，就会抛出NoSuchBeanDefinitionException异常
//        TeaService teaService = (TeaService) context.getBean("teaService02");
//        System.out.println(teaService);
        //3、调用Bean对象的方法
//        teaService.method();
//        teaService.method();

//        TeaService teaService2 = (TeaService) context.getBean("teaService02");
//        System.out.println(teaService2);
//        //3、调用Bean对象的方法
//        teaService2.method();
//        teaService2.method();


        //TeaDao teaDao = (TeaDao) context.getBean("teaDao");
        //teaDao.teaDaoMethod();


//        TeaService t1 = (TeaService) context.getBean("teaService");
//        System.out.println(t1);
//        TeaService t2 = (TeaService) context.getBean("teaService");
//        System.out.println(t2);


        //OrderDao orderDao = (OrderDao)context.getBean("orderDao");
        //orderDao.save();

        //System.out.println("=========================================================");
        //OrderDao orderDao02 = (OrderDao)context.getBean("orderDao02");
        //orderDao02.save();

        //System.out.println("=========================================================");
        OrderDao orderDao03 = (OrderDao)context.getBean("orderDao03");
        orderDao03.save();

    }
}
